package cn.com.lms.business.examRewrite.persistence.repository;

import cn.com.lms.business.examRewrite.persistence.entity.ExerciseReWrite;
import com.bnzj.core.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;






@Repository
public interface ExerciseReWriteDao extends BaseRepository<ExerciseReWrite, Long> {

    /**
     * 启用
     * @param result true
     * @param id
     * @return
     */
    @Query(nativeQuery = true,value = "UPDATE bnz_exam_exercise SET is_enable = :result WHERE id = :id")
    @Modifying // 更新操作
    int enableById(@Param("result") Boolean result, @Param("id") List<Long> id);

    /**
     * 禁用
     * @param result false
     * @param id
     * @return
     */
    @Query(nativeQuery = true,value = "UPDATE bnz_exam_exercise SET is_enable = :result WHERE id = :id")
    @Modifying // 更新操作
    int disableById(@Param("result") Boolean result, @Param("id") List<Long> id);

    /**
     * 删除、批量删除
     * @param result true
     * @param id
     * @return
     */
    @Query(nativeQuery = true,value = "UPDATE bnz_exam_exercise SET is_delete = :result WHERE id in (:id)")
    @Modifying // 删除操作
    Integer deletesById(@Param("result") boolean result, @Param("id") List<Long> id);

    /**
     * 通过名字(name)和创建人(creator)查询
     * @param exerciseName
     * @param id
     */
    @Query(nativeQuery = true,value = "SELECT * FROM bnz_exam_exercise WHERE is_delete = false AND exercise_name = :exerciseName AND creator = :id")
    List<ExerciseReWrite> getExerciseReWritesByNameAndCreator(@Param("exerciseName") String exerciseName, @Param("id") Long id);



}
